import { useEffect, useState } from 'react';
import { useRequest } from 'umi';

export type getLikePropType = {
  field: string;
  key: string;
  level: string;
};

export default function UseGetLike() {
  const countryTypeRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'countryType' },
    };
  });

  const countryRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'country' },
    };
  });

  const genderRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'gender' },
    };
  });
  const idTypeRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'idType' },
    };
  });
  const nationRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'nation' },
    };
  });

  const politicalStatusRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'politicalStatus' },
    };
  });
  const unitRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'unit' },
    };
  });
  const topEducationMajorRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'topEducationMajor' },
    };
  });
  const technicalGradeRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'technicalGrade' },
    };
  });
  const technicalNameRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'technicalName' },
    };
  });
  const positionRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'position' },
    };
  });

  const topDegreeRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'topDegree' },
    };
  });
  const topEducationRequest = useRequest((prop = {}) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data: { ...prop, field: 'topEducation' },
    };
  });
  const [countryType, setCountryType] = useState(countryTypeRequest.data);
  const [country, setCountry] = useState(countryRequest.data);
  const [nation, setNation] = useState(nationRequest.data);
  const [politicalStatus, setPoliticalStatus] = useState(
    politicalStatusRequest.data,
  );
  const [idType, setIdType] = useState(idTypeRequest.data);
  const [unit, setUnit] = useState(unitRequest.data);
  const [topEducationMajor, setTopEducationMajor] = useState(
    topEducationMajorRequest.data,
  );
  const [technicalGrade, setTechnicalGrade] = useState(
    technicalGradeRequest.data,
  );
  const [technicalName, setTechnicalName] = useState(technicalNameRequest.data);
  const [position, setPosition] = useState(positionRequest.data);
  const [topDegree, setTopDegree] = useState(topDegreeRequest.data);
  const [topEducation, setTopEducation] = useState(topEducationRequest.data);

  // countryTypeRequest.run().then((data) => { setCountryType(data) })
  // countryRequest.run().then((data) => { setCountry(data) })
  // nationRequest.run().then((data) => { setNation(data) })
  // politicalStatusRequest.run().then((data) => { setPoliticalStatus(data) })
  // idTypeRequest.run().then((data) => { setIdType(data) })
  // unitRequest.run().then((data) => { setUnit(data) })
  // topEducationMajorRequest.run().then((data) => { setTopEducationMajor(data) })
  // technicalGradeRequest.run().then((data) => { setTechnicalGrade(data) })
  // technicalNameRequest.run().then((data) => { setTechnicalName(data) })
  // positionRequest.run().then((data) => { setPosition(data) })
  // topDegreeRequest.run().then((data) => { setTopDegree(data) })
  // topEducationRequest.run().then((data) => { setTopEducation(data) })

  return {
    countryType: countryTypeRequest.data,
    country: countryRequest.data,
    idType: idType,
    nation: nation,
    politicalStatus: politicalStatus,
    unit: unit,
    topEducationMajor: topEducationMajor,
    technicalGrade: technicalGrade,
    technicalName: technicalName,
    position: position,
    topDegree: topDegree,
    topEducation: topEducation,
  };
}
